package com.example.aixiangshou.runninggame;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.x_memteor.base_master.application.MyApplication;
import com.x_memteor.base_master.base.BaseActivity;
import com.x_memteor.base_master.bean.GameBean;

import butterknife.BindView;
import butterknife.OnClick;

public class SelectGameActivity extends BaseActivity implements CompoundButton.OnCheckedChangeListener{

    @BindView(R.id.checkbox_roulette)
    CheckBox checkboxRoulette;
    @BindView(R.id.tv_roulette)
    TextView tvRoulette;
    @BindView(R.id.lay_roulette)
    LinearLayout layRoulette;
    @BindView(R.id.checkbox_cards)
    CheckBox checkboxCards;
    @BindView(R.id.tv_cards)
    TextView tvCards;
    @BindView(R.id.lay_cards)
    LinearLayout layCards;
    @BindView(R.id.tv_back)
    TextView tvBack;
    @BindView(R.id.tv_next)
    TextView tvNext;

    boolean isRoulette = false;
    boolean isCards = false;

    int gameType;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void initRootView() {
        setContentView(R.layout.activity_select_game);
    }

    @Override
    public void initView() {

    }

    @Override
    public void initData() {

    }

    @Override
    public void initListener() {
        checkboxRoulette.setOnCheckedChangeListener(this);
        checkboxCards.setOnCheckedChangeListener(this);
    }

    @OnClick({R.id.tv_back, R.id.tv_next})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_back:
                finish();
                break;
            case R.id.tv_next:
                MyApplication.getInstance().getGameBean().setGameType(gameType);
                startActivity(new Intent(SelectGameActivity.this,ChooseItemActivity.class));
                break;
        }
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        switch (buttonView.getId()) {
            case R.id.checkbox_roulette:
                if (isChecked) {
                    isRoulette = true;
                    gameType = GameBean.GAME_TYPE_ROULETTE;
                    if (isCards){
                        checkboxCards.setChecked(false);
                    }
                    buttonView.setBackgroundColor(getResources().getColor(R.color.main_sky));
                    tvRoulette.setBackgroundColor(getResources().getColor(R.color.main_blue));
                } else {
                    isRoulette = false;
                    buttonView.setBackgroundColor(getResources().getColor(R.color.main_fense));
                    tvRoulette.setBackgroundColor(getResources().getColor(R.color.main_gray));
                }
                break;
            case R.id.checkbox_cards:
                if (isChecked) {
                    isCards = true;
                    gameType = GameBean.GAME_TYPE_CARD;
                    if (isRoulette){
                        checkboxRoulette.setChecked(false);
                    }
                    buttonView.setBackgroundColor(getResources().getColor(R.color.main_sky));
                    tvCards.setBackgroundColor(getResources().getColor(R.color.main_blue));
                } else {
                    isCards = false;
                    buttonView.setBackgroundColor(getResources().getColor(R.color.main_fense));
                    tvCards.setBackgroundColor(getResources().getColor(R.color.main_gray));
                }
                break;
        }
    }
}
